<template>
    <section>
        <div class="order-container">
            <div class="header">
                <h4>所有订单</h4>
            </div>
            <div class="order-con">
                <el-tabs v-model="activeTab" @tab-click="handleClick" style="">
                    <el-tab-pane label="全部" name="0"></el-tab-pane>
                    <el-tab-pane label="退款处理中" name="1"></el-tab-pane>
                    <el-tab-pane label="退款成功" name="2"></el-tab-pane>
                    <el-tab-pane label="退款关闭" name="3"></el-tab-pane>
                </el-tabs>
                <div class="order-con__title flex-box">
                    <el-input v-model="orderName" placeholder="订单号/退款号" style="width:300px;"></el-input>
                    <el-date-picker
                            v-model="orderTime"
                            type="datetime"
                            style="min-width:150px;"
                            placeholder="退款申请日期">
                    </el-date-picker>
                    <el-select v-model="orderOption" placeholder="请选择">
                        <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                    <el-button type="primary" @click="searchItem" icon="el-icon-search"></el-button>
                    <el-button type="primary" @click="outItem">批量导出</el-button>
                </div>
                <div class="table-box">
                    <el-table :data="orderList" v-loading="tableLoading" style="width: 100%">
                        <el-table-column :resizable="false" label="退款编号" prop="sn">
                        </el-table-column>
                        <el-table-column :resizable="false" label="退款方式" prop="refund_way">
                        </el-table-column>
                        <el-table-column :resizable="false" label="订单编号/商品" prop="order_sn">
                        </el-table-column>
                        <el-table-column :resizable="false" label="订单金额" prop="order_amount">
                        </el-table-column>
                        <el-table-column :resizable="false" label="退款金额" prop="refund_amount">
                        </el-table-column>
                        <el-table-column :resizable="false" label="申请时间" prop="apply_time" sortable>
                        </el-table-column>
                        <el-table-column :resizable="false" label="退款状态" prop="order_state">
                        </el-table-column>
                        <el-table-column :resizable="false" prop="operation" label="操作" width="180">
                            <template slot-scope="scope">
                                <el-button @click="agreeOpera(scope.row.id,scope.row)" type="primary" size="mini">同意</el-button>
                                <el-button @click="refuseOpera(scope.row.id,scope.row)" type="primary" size="mini" plain>拒绝</el-button>
                                <!--<span>已拒绝</span>-->
                                <!--<span>已同意</span>-->
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="pagination" v-if="page.total">
                    <div>
                        共{{page.count}}页，每页{{pageSize}}条
                    </div>
                    <el-pagination layout="prev, pager, next" :total="page.total" prev-text="上一页"
                                   next-text="下一页" :page-size="pageSize"
                                   @current-change="handleCurrentChange">
                    </el-pagination>
                </div>
            </div>

        </div>
    </section>
</template>

<script>
    export default {
        components: {},
        data() {
            return {
                activeTab: '0',

                orderTime: '',
                orderName: '',
                orderOption: '',
                options: [
                    {label: '已退款', value: '0'},
                    {label: '退款申请中', value: '1'}
                ],

                orderList: [],
                tableLoading: true,

                pageCount: '',
                page: {
                    total: '',
                    count: ''
                },
                pageSize: 20,
            }
        },
        watch: {},
        computed: {},
        mounted() {
            this.getOrderList();
        },
        methods: {
            handleClick() {
                this.getOrderList();
            },
            genItem(data) {
                axios
                    .get('admin_goods', {
                        params: data
                    })
                    .then(res => {
                        this.page.total = res.data.count;
                        this.page.count = Math.ceil(res.data.count / this.pageSize);
                        return res;
                    })
                    .then(res => res.data.data)
                    .then(res => {
                        console.log('数据', res)
                        this.orderList = res;
                        this.tableLoading = false;
                    })
            },
            searchItem() {
                console.log('订单号',this.orderName,'时间',this.orderTime,'状态',this.orderOption)
                const data = {
                    pagination: 1,
                    pageSize: this.pageSize,
                    activeTab: this.activeTab,
                    name: this.orderName,
                    time: this.orderTime,
                    status:this.orderOption
                }
                this.genItem(data)
            },
            getOrderList() {
                const data = {
                    pagination: 1,
                    pageSize: this.pageSize,
                    activeTab: this.activeTab
                }
                this.genItem(data)
            },
            outItem() {
                console.log("批量导出")
            },
            agreeOpera(id,row) {
                console.log('同意')
                // this.$confirm('是否确认删除该商品?', '提示', {
                //     confirmButtonText: '确定',
                //     cancelButtonText: '取消',
                //     type: 'warning'
                // })
                //     .then(() => {
                //         return axios
                //             .post(`admin_goods/${id}`, {_method: 'PUT'})
                //             .then(
                //                 res => (res.data.status === 1 ? Promise.resolve() : Promise.reject(res.data.msg))
                //             );
                //     })
                //     .then(() => {
                //         this.$message({
                //             type: 'success',
                //             message: '操作成功!'
                //         });
                //         this.getOrderList();
                //     })
                //     .catch(err => {
                //         if (err !== 'cancel') {
                //             this.$message.error(err);
                //         }
                //     });
            },
            refuseOpera(id,row){
                console.log('拒绝')
            },
            // genData(data) {
            //     return {
            //         sort: data.sort,
            //         shop_id: data.shop_id,
            //         image: data.image ? data.image.join(',') : '',
            //         is_in_list: data.is_in_list,
            //         name: data.name,
            //     };
            // },
            // postData() {
            //     return axios
            //         .post('admin_goods', this.genData(this.form))
            //         .then(res => {
            //             return res.data.status === 1 ? Promise.resolve() : Promise.reject(res.data.msg);
            //         });
            // },
            handleCurrentChange(current) {
                this.getOrderList(current);
            }
        }
    }
</script>
<style scoped>
    .order-container {
        min-height: calc(100vh - 92px);
    }

    .flex-box {
        display: flex;
    }

    .flex-box-display {
        justify-content: space-between;
    }

    .header {
        padding: 10px;

        background: #FFFFFF;
    }

    .order-con {
        margin: 10px;
        padding: 20px;
        background: #FFFFFF;
    }

    .order-con__title {
        padding-bottom: 10px;
        border-bottom: 1px dashed #D8D8D8;
    }

    .table-box {
        min-height: calc(100vh - 92px);
    }

    .pagination {
        display: flex;
        align-items: center;
        justify-content: space-around;

        width: 100%;
    }


</style>
<style>

</style>